#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:studentModel.py
# author:Jackiex
# datetime:2023/5/18 14:44
# software: PyCharm

"""
this is function  description 
"""

from sqlalchemy import Column, DateTime, String, Integer, and_, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import FetchedValue

Base = declarative_base()
metadata = Base.metadata

from . import session


class StudentModel(Base):
    __tablename__ = 'student'

    autoID = Column(Integer, primary_key=True)
    studentID = Column(String(20), info='学生ID')
    name = Column(String(20), info='学生姓名')
    age = Column(Integer, info='学生年龄')
    classID = Column(Integer, info='学生所属班级ID')
    agenda = Column(String(4), info='性别')
    isDelete = Column(Integer, server_default=FetchedValue(), info='是否删除')
    addTime = Column(DateTime, server_default=FetchedValue(), info='记录添加时间')

    # 增加记录
    @classmethod
    def add_student(cls, **kwargs):

        try:
            student = StudentModel(
                studentID=kwargs.get('studentID'),
                name=kwargs.get('name'),
                age=kwargs.get('age'),
                classID=kwargs.get('classID'),
                agenda=kwargs.get('agenda')
            )

            session.add(student)
            session.commit()

        except Exception as e:
            print(e)

        return {'code': 200, 'message': 'OK'}

    # 删除
    @classmethod
    def delete_student(cls, **kwargs):
        pass

    @classmethod
    def get_student(cls):
        pass
